﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using olierFrm.GeneralCache;

namespace olierFrm.DataBase.FrameWork.DataDictornary
{
public class DataWrapperLookup : DefinedSQL
{
    
    public const string WrapperLookupCachePrefix = "WrapperLookup=";

    
    public DataWrapperLookup(string wrapperName)
    {
        string CacheKey = "WrapperLookup=" + wrapperName;
        if (!Cache.KeyExists(CacheKey))
        {
            List<WF_DataLinkItems> dwl = (from d in base.DBEntity.WF_DataLinkItems
                where d.WrapperName == wrapperName
                select d).ToList<WF_DataLinkItems>();
            if (dwl.Count<WF_DataLinkItems>() != 0)
            {
                Cache.Add(CacheKey, dwl);
            }
        }
        this.WrapperLookups = (List<WF_DataLinkItems>) Cache.Get(CacheKey);
    }

    public List<WF_DataLinkItems> FindByLookupField(string lookupField)
    {
        var dwl = from d in this.WrapperLookups
            where d.LookupField == lookupField
            select d;
        if (dwl.Count<WF_DataLinkItems>() != 0)
        {
            return dwl.ToList<WF_DataLinkItems>();
        }
        return null;
    }

    public List<string> GetDataObjects(WF_DataLinkItems dwl)
    {
        return dwl.DataObject.Split(new char[] { ';' }).ToList<string>();
    }

    
    public List<WF_DataLinkItems> WrapperLookups { get; set; }
}

 

 

}